package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import panels.*;

public class MainFrame extends JFrame{

	public static final int WIDTH = 1024;
    public static final int HEIGHT = 768;
    
    private JPanel middleP;

	public CardLayout change;
    
	public LoginPanel loggy;      // renamed because "login" is reserved
	public BloggerPanel blogger;
	public CalendarPanel calendar;
	public GmailPanel gmail;
	public PicasaPanel picasa;
	public DocsPanel docs;
    
	
	public MainFrame()
	{
		setTitle("Google Services Desktop Application alpha v1.0");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(WIDTH, HEIGHT);
        setLayout(new BorderLayout());
        
        //Instructions
        JPanel buttons = new JPanel();
        buttons.setLayout(new GridLayout(5, 1));
        
        //Buttons for each service
        JButton bloggerB = new JButton("Blogger");
        bloggerB.addActionListener(new bloggerListener());
        buttons.add(bloggerB);
        
        JButton gmailB = new JButton("Gmail");
        gmailB.addActionListener(new gmailListener());
        buttons.add(gmailB);
        
        JButton picasaB = new JButton("Picasa");
        picasaB.addActionListener(new picasaListener());
        buttons.add(picasaB);
        
        JButton calendarB = new JButton("Calendar");
        calendarB.addActionListener(new calendarListener());
        buttons.add(calendarB);
        
        JButton docsB = new JButton("Docs");
        docsB.addActionListener(new docsListener());
        buttons.add(docsB);
        
        //Adds buttons to left side
        add(buttons, BorderLayout.WEST);
        
        //Creates panel that hold all 5 services
        middleP = new JPanel();
        middleP.setLayout(new CardLayout());
        
        //change controls what the "cards" in the CardLayout do
        change = (CardLayout)(middleP.getLayout());
        
        //Default panel is login
        loggy = new LoginPanel(change, middleP);
        middleP.add(loggy.panel, "Login_Panel");

        /*
        //Welcome panel  
        welcome = new welcomeGUI();
        middleP.add(welcome.panel, "Welcome_Panel");
        */
        
        //Blogger panel  
        blogger = new BloggerPanel();
        middleP.add(blogger.panel, "Blogger_Panel");
        
        
        //Gmail panel
        gmail = new GmailPanel();
        middleP.add(gmail.panel, "Gmail_Panel");
        
        //Picasa panel
        picasa = new PicasaPanel();
        middleP.add(picasa.panel, "Picasa_Panel");
        
        
        //Calendar panel
        calendar = new CalendarPanel();
        middleP.add(calendar.panel, "Calendar_Panel");
        
        //Docs panel
        docs = new DocsPanel();
        middleP.add(docs.panel, "Docs_Panel");

        //Adds the center panel
        add(middleP, BorderLayout.CENTER);
        
        
        //Top menu
        JMenuBar bar = new JMenuBar();
        
        JMenu file = new JMenu("File");
        
        JMenuItem logout = new JMenuItem("Log out");
        logout.addActionListener(new logoutListener());
        
        JMenuItem exit = new JMenuItem("Exit");
        exit.addActionListener(new exitListener());
        
        file.add(logout);
        file.add(exit);
        bar.add(file);
        
        setJMenuBar(bar);
    }
	
	private class logoutListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			change.show(middleP, "Login_Panel");
		}
	}
	
	private class exitListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			System.exit(0);
		}
	}
	
	private class bloggerListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			change.show(middleP, "Blogger_Panel");
		}
	}
	
	private class gmailListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			change.show(middleP, "Gmail_Panel");
		}
	}
	
	private class picasaListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			change.show(middleP, "Picasa_Panel");
		}
	}
	
	private class calendarListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			change.show(middleP, "Calendar_Panel");
		}
	}
	
	private class docsListener implements ActionListener {
		public void actionPerformed(ActionEvent e) 
        {
			change.show(middleP, "Docs_Panel");
		}
	}

    /**
    *  Main
    *
    */
	public static void main() {
		MainFrame myGUI = new MainFrame( );
		myGUI.setVisible(true);
	}
}
